import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/material_footer.dart';
import 'package:flutter_module/config/ServiceUlr.dart';
import 'package:flutter_module/view_model/query_wuliao.dart';
import 'package:flutter_module/view_model/wuliaoming.dart';
import 'package:flutter_module/widget/provider_widget.dart';
import 'package:flutter_module/widget/tap_appbar.dart';
import 'package:flutter_screenutil/screenutil.dart';


class KuFangMing extends StatefulWidget {
  @override
  _KuFangMing createState() => _KuFangMing();
}

class _KuFangMing extends State<KuFangMing> {
  List<List> list = [];
  var map = {
    "1": "交通维护类",
    "2": "水管接头",
    "3": "水泵控制柜",
    "4": "工作服",
    "5": "安全救生",
    "6": "小工具",
    "7": "排水专用工具",
    "8": "其他",
    "9": "全部",
    "1001": "讯腾物料1",
    "1002": "讯腾物料2"
  };

  var map1 ={
    "materielType":"",
    "materielNo":"",
    "materielName":"",
    "pageIndex":"1",
    "pageSize":"10",
    "companyId":"402880185889ef6e015889f8c51e0000",
    "userId":"8a2a2a295c1ec767015c2ddd9d1e0001",
  };


//  String value;
  var xmbValue;
  var gcztValue;
  var xzValue;
  String materielName;
  String materielType;
  var sgfeValue;
  var sDate = " ";
  var eDat = "";
  String materielNo = "";
  wuliaoQueryModel queryModel= new wuliaoQueryModel();

  @override
  void initState() {
    // TODO: implement initState

  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TapAppBar(TapViewBar(Text("选择库房名称"
          ""), icon: Icon(Icons.arrow_back)),
          Size.fromHeight(ScreenUtil().setHeight(80))),
      body: ProviderWidget<wuliaoQueryming>(
        model: wuliaoQueryming(),onModelInit: (model){
//        model.url = "selectMateriels";
        model.getHttpData(servicePath["selectStorehouses"]).then((value) {
          list = model.data;
        });
      }, builder: (context, model, child) {
        return EasyRefresh(
            controller: model.controller,
            footer: MaterialFooter(),
            enableControlFinishLoad: true,
            onLoad:model.onLoad,
            bottomBouncing: true,
            child: SingleChildScrollView(
              child: Column(
                children: <Widget>[
                  getItem("序号", map),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
//                  getInPutName(),
//                  SizedBox(height: 1,
//                    width: ScreenUtil().setWidth(700),
//                    child: Container(color: Colors.black12,),),
                  getInPutName1(),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getQuery(model),
                  getWrap(),
                ],
              ),
            ));
      },
      ),
    );
  }
  List<Widget> getListItem(){
    return list.map((value){
      return Container(
        margin: EdgeInsets.only(left: 10, right: 10,top: 10),
        padding: EdgeInsets.only(left: 20,top: 10),
        decoration: new BoxDecoration(
          //背景
          color: Colors.white,
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(4.0)),
          //设置四周边框
//          border: new Border.all(width: 1, color: Colors.red),
        ),
//        color: Colors.white,
        child: InkWell(
            onTap: (){
              Navigator.pop(context,value[0] +"-"+value[1]);
            },
            child: Column(
              children: <Widget>[
                getListItemData("名        称:", value[1]),
                SizedBox(height: 10,),

              ],
            )),
      );


    }).toList();
  }
  Widget getListItemData(String name,String data){
    return Row(
      children: <Widget>[
        Expanded(child: Text(name,style: TextStyle(fontWeight: FontWeight.bold),),flex: 1,),
        Expanded(child: Text(data,style: TextStyle(color: name == "状        态:"?Colors.red:Colors.black54),),flex: 4,)
      ],
    );
  }

  Widget getDownButton(Map<String,String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value), value: key));
    });
    return DropdownButtonHideUnderline(child:
    DropdownButton(
        items: list1,
        value: materielType,
        onChanged: (value) {
          setState(() {
            this.materielType = value;
          });
        })
    );
  }


  Widget getItem(String title, Map<String,String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(120),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(child: Text(title), flex: 1,),
          Expanded(child: getDownButton(list), flex: 2,)
        ],
      ),
    );
  }

  Widget getInPutName() {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(120),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(child: Text("编号"), flex: 1,),
          Expanded(child: TextField(
            decoration: InputDecoration(
              //  labelText: sp.getUserInfo("num").toString(),
              // fillColor: Colors.black12,
              fillColor: Colors.white,
              filled: true,
              border: InputBorder.none,
              hintText: "",
            ),
            onChanged: (value) {
              materielNo = value;
            },
          ), flex: 2,)

        ],
      ),
    );
  }

  Widget getInPutName1() {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(120),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(child: Text("库房名称"), flex: 1,),
          Expanded(child: TextField(
            decoration: InputDecoration(
              //  labelText: sp.getUserInfo("num").toString(),
              fillColor: Colors.white,
              filled: true,
              border: InputBorder.none,
              hintText: "",
            ),
            onChanged: (value) {
              materielName = value;
            },
          ), flex: 2,)

        ],
      ),
    );
  }


  Widget getQuery(wuliaoQueryming model) {
    return Container(
      // color: Colors.black12,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(120),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(child:
          RaisedButton(
            onPressed: () {
              var map ={
                "materielType":this.materielType,
                "materielNo":materielNo,
                "materielName":materielName,
                "pageIndex":"1",
                "pageSize":"10",
                "companyId":"402880185889ef6e015889f8c51e0000",
                "userId":"8a2a2a295c1ec767015c2ddd9d1e0001",
              };
              model.map=map;
              model.query = false;
              model.getHttpData(servicePath["selectStorehouses"],data: map);

            },
            child: Text("查询")
            ,
            textColor: Colors.white,
            color: Theme
                .of(context)
                .primaryColor,

            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
              // side: BorderSide(color: Colors.red)
            ),),
            flex: 1,),
//          Text("   "),


        ],
      ),
    );
  }

  Widget getWrap() {
    if(list==null){
      return
        Text(" ");
    }else{
      return Container(
//        padding: EdgeInsets.only(left: 30),
        child: Wrap(
          spacing: 1,
          children: getListItem(),
        ),
      );
    }
  }
}

